

//
//  DidMainNavView.m
//  didihaha
//
//  Created by 赵忠鹏 on 2017/8/21.
//  Copyright © 2017年 zhaozhongpeng. All rights reserved.
//

#import "DidMainNavView.h"
#import "Masonry.h"
@implementation DidMainNavView

- (instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self createUI];
    }
    return self;
}

- (void)createUI{
    [self addSubview:self.personMessageBtn];
    [self addSubview:self.notificationBtn];
    [self addSubview:self.topMessageLabel];
    [self addSubview:self.moreBtn];
    [self addSubview:self.carLable];
    
    [self.personMessageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(20);
        make.top.equalTo(self.mas_top).offset(35);
        make.height.width.mas_equalTo(25);
    }];
    
    [self.notificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.equalTo(self.personMessageBtn);
        make.right.equalTo(self.mas_right).offset(-15);
    }];
    
    [self.topMessageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self.personMessageBtn.mas_centerY);
    }];
    
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.width.height.equalTo(self.notificationBtn);
        make.top.equalTo(self.notificationBtn.mas_bottom).offset(12);
    }];
    
    [self.carLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.personMessageBtn.mas_left);
        make.right.equalTo(self.notificationBtn.mas_right);
        make.centerY.equalTo(self.moreBtn.mas_centerY);
    }];
    
}

#pragma 懒加载

- (UIButton *)personMessageBtn{
    if (_personMessageBtn == nil) {
        _personMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_personMessageBtn setImage:[UIImage imageNamed:@"round_menu_btn_normal"] forState:UIControlStateNormal];
    }
    return _personMessageBtn;
}

- (UIButton *)notificationBtn{
    if (_notificationBtn == nil) {
        _notificationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_notificationBtn setImage:[UIImage imageNamed:@"message_icon_entrance_normal"] forState:UIControlStateNormal];
    }
    return _notificationBtn;
}

- (UILabel *)topMessageLabel{
    if (_topMessageLabel == nil) {
        _topMessageLabel = [[UILabel alloc] init];
        _topMessageLabel.font = [UIFont systemFontOfSize:12];
        _topMessageLabel.textColor = [UIColor colorWithRed:115/255.0 green:115/255.0 blue:115/255.0 alpha:1];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"北京市  "];
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        //定义图片内容及位置和大小
        attch.image = [UIImage imageNamed:@"member_default_icon"];
        attch.bounds = CGRectMake(0, -8, 25, 25);
        //创建带有图片的富文本
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        
        NSTextAttachment *attchTwo = [[NSTextAttachment alloc] init];
        //定义图片内容及位置和大小
        attchTwo.image = [UIImage imageNamed:@"sc_open_grid_info"];
        attchTwo.bounds = CGRectMake(0, 2, 6, 4);
        //创建带有图片的富文本
        NSAttributedString *stringTwo = [NSAttributedString attributedStringWithAttachment:attchTwo];
        
        [attri insertAttributedString:string atIndex:0];
        [attri appendAttributedString:stringTwo];
        
        _topMessageLabel.attributedText = attri;
        
    }
    return _topMessageLabel;
}

- (UIButton *)moreBtn{
    if (_moreBtn == nil) {
        _moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_moreBtn setImage:[UIImage imageNamed:@"secondnavigation_btn_more"] forState:UIControlStateNormal];
    }
    return _moreBtn;
}

-(UILabel *)carLable{
    if (_carLable == nil) {
        _carLable = [[UILabel alloc] init];
        _carLable.font = [UIFont systemFontOfSize:14];
        _carLable.textColor = [UIColor colorWithRed:115/255.0 green:115/255.0 blue:115/255.0 alpha:1];
        NSString *tempStr = @"出租车      ofo单车      豪华车      快车      顺风车      专车";
        NSMutableAttributedString *tempAtt = [[NSMutableAttributedString alloc] initWithString:tempStr];
        [tempAtt setAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} range:[tempStr rangeOfString:@"出租车"]];
        _carLable.attributedText = tempAtt;
        
    }
    return _carLable;
}

@end
